import axios from 'axios'
import store from '@/store'
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API
})

// 请求拦截器
service.interceptors.request.use(function(config) {
  console.log('所有的请求都经过我', config)
  const token = store.state.user.token
  config.headers.Authorization = `Bearer ${token}`

  return config
}, function(error) {
  console.log('123', error)
})
// 响应拦截器
service.interceptors.response.use(function(response) {
  console.log(response, '456')
  if (!response.data.success) {
    return Promise.reject(response.data.message)
  }
  return response
}, function(error) {
  return Promise.reject(error)
})
export default service
